package org.example.response;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;
import org.example.entity.Order;

import java.util.ArrayList;
import java.util.List;

@Data
public class ServerResponse<T> {
    private Integer code;
    private String msg;
    private Long count;
    private List<T> data = new ArrayList<T>();

    private ServerResponse(int code, String msg, Long count, List<T> data) {
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = data;

    }

    public static <T> String success(List<T> data,Long count){
       JSONObject.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd";
       return JSON.toJSONString(new ServerResponse(0,"success",count,data),SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
    }
}
